from datetime import datetime

def check_order(house,start_date,end_date):
    fmt = '%Y-%m-%d'
    ret = 0
    start_day = datetime.strptime(str(start_date), fmt).date()
    end_day = datetime.strptime(str(end_date), fmt).date()
    for order in house.order_set.all():
        if (start_day - order.begin_date).days > 0 and (start_day - order.end_date).days < 0:
            break
        elif (end_day - order.begin_date).days > 0 and (end_day - order.end_date).days < 0:
            break
        elif (start_day - order.begin_date).days < 0 and (end_day - order.end_date).days > 0:
            break
        else:
            break
    else:
        ret=1
    return ret
